package com.eco.fanliapp.admin.controller.web;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.eco.fanliapp.admin.annotation.SysLogAnnotation;
import com.eco.fanliapp.common.response.ServerResponse;
import com.eco.fanliapp.entity.AppUserRewardSetup;
import com.eco.fanliapp.entity.SyTaskType;
import com.eco.fanliapp.service.IAppUserRewardSetupService;
import com.eco.fanliapp.service.ISyTaskTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 红包方案设置
 */
@RestController
@RequestMapping("/web/appUserRewardSetup")
public class AppUserRewardSetupController {


    @Autowired
    private IAppUserRewardSetupService appUserRewardSetupService;
    @Autowired
    private ISyTaskTypeService iSyTaskTypeService;

    @RequestMapping(value = "add", method = RequestMethod.POST)
    @SysLogAnnotation(value = "红包方案修改",userType = 2)
    public ServerResponse addAppUserRewardSetup(@RequestBody AppUserRewardSetup appUserRewardSetup) {
        int i = appUserRewardSetupService.addAppUserRewardSetup(appUserRewardSetup);
        if(i > 0){
            iSyTaskTypeService.updateTaskRewardMoneyById(appUserRewardSetup.getTaskRedMoneyAmount(),2);
            iSyTaskTypeService.updateTaskRewardMoneyById(appUserRewardSetup.getInvitationRedMoneyAmount(),5);
        }
        if (i <= 0) return ServerResponse.createByErrorMessage("红包方案保存失败");
        return ServerResponse.createBySuccessMessage("红包方案保存成功");
    }
    @RequestMapping(value = "update", method = RequestMethod.POST)
    @SysLogAnnotation(value = "红包方案修改",userType = 2)
    public ServerResponse updateAppUserRewardSetup(@RequestBody AppUserRewardSetup appUserRewardSetup) {
        int i = appUserRewardSetupService.updateAppUserRewardSetup(appUserRewardSetup);
        if(i > 0){
           iSyTaskTypeService.updateTaskRewardMoneyById(appUserRewardSetup.getTaskRedMoneyAmount(),2);
           iSyTaskTypeService.updateTaskRewardMoneyById(appUserRewardSetup.getInvitationRedMoneyAmount(),5);
        }

        if (i <= 0) return ServerResponse.createByErrorMessage("红包方案保存失败");
        return ServerResponse.createBySuccessMessage("红包方案保存成功");
    }
    @RequestMapping(value = "list", method = RequestMethod.GET)
    public ServerResponse selectAppUserRewardSetup() {
        List<AppUserRewardSetup>  appUserRewardSetupServiceList = appUserRewardSetupService.selectAppUserRewardSetup();
        return ServerResponse.createBySuccess("数据获取成功", appUserRewardSetupServiceList);
    }
    @RequestMapping(value = "getAppUserRewardSetup", method = RequestMethod.GET)
    public ServerResponse getAppUserRewardSetup() {
        AppUserRewardSetup appUserRewardSetup = appUserRewardSetupService.getAppUserRewardSetup(1);
        return ServerResponse.createBySuccess("数据获取成功", appUserRewardSetup);
    }
}
